package com.xintong.visualinspection.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xintong.system.err.BusinessException;
import com.xintong.visualinspection.bean.TeamClass;
import com.xintong.visualinspection.service.TeamClassService;

/**
 * 文件名：TestController
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@RestController
@RequestMapping("/teamClass")
public class TeamClassController extends BaseController {

    @Autowired
    private TeamClassService teamClassService;

   
    /**
     * 添加班次
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/add")
    public String add(@Valid @RequestBody TeamClass teamClass){
    	teamClassService.insert(teamClass);
    	return super.returnSuccessResult("添加成功");
    }
    
    /**
     * 修改班次
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/update")
    public String update(@Valid @RequestBody TeamClass teamClass){
    	teamClassService.update(teamClass);
    	return super.returnSuccessResult("修改成功");
    }
    
    /**
     * 删除班次
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/delete")
    public String delete(@RequestBody TeamClass teamClass){
    	teamClassService.delete(teamClass.getId());
    	return super.returnSuccessResult("删除成功");
    }
    
    /**
     * 通过id获取班次
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getClassById")
    public String getClassById(@RequestBody TeamClass teamClass){
    	if(teamClass.getId()==null){
    		throw new BusinessException(20002);
    	}
    	TeamClass tc = teamClassService.getById(teamClass.getId());
    	return super.returnSuccessResult(tc);
    }
    
    /**
     * 通过多个条件查询班次
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getClassList")
    public String getClassList(@RequestBody TeamClass teamClass){
    	if(teamClass.getDept_id()==null){
    		throw new BusinessException(20901);
    	}
    	if(teamClass.getStart_time()==null){
    		throw new BusinessException(20902);
    	}
    	if(teamClass.getEnd_time()==null){
    		throw new BusinessException(20903);
    	}
    	List<TeamClass> tcList = teamClassService.getClassList(teamClass);
    	return super.returnSuccessResult(tcList);
    }
}
